Update Readme.md
[EroSomnia.git] / Point and Click Game1 / MouseIO.cpp
blobacab3a41c3e594317381dbf1fbcba19d625897ee
1 #include "MouseIO.h"
2 #include <iostream>
4 #define NUMBER_OF_INPUTS 33
5 #define LCLICK inputArray.at(LEFTMOUSECLICKED) && !inputArray.at(LEFTMOUSEHELD)
6 #define LHELD inputArray.at(LEFTMOUSEHELD)
7 #define RCLICK inputArray.at(RIGHTMOUSECLICKED) && !inputArray.at(RIGHTMOUSEHELD)
8 #define RHELD inputArray.at(RIGHTMOUSEHELD)
10 MouseIO::MouseIO()
12 inputArray.reserve(NUMBER_OF_INPUTS);
13 for (int i = 0; i < NUMBER_OF_INPUTS; i++) {
14 inputArray.push_back(false);
17 distanceCounter = 0;
18 oldX = -1;
19 oldY = -1;
23 MouseIO::~MouseIO()
27 //Returns a pointer to the origional array
28 std::vector<bool>* MouseIO::processMouseInput(int * x, int * y) {
29 //std::cout << inputArray[MOUSECLICKED];
30 if (inputArray[MOUSECLICKED] == true) inputArray[MOUSEHELD] = true;
31 else inputArray[MOUSEHELD] = false;
32 if (inputArray[LEFTMOUSECLICKED] == true) inputArray[LEFTMOUSEHELD] = true;
33 else inputArray[LEFTMOUSEHELD] = false;
34 if (inputArray[RIGHTMOUSECLICKED] == true) inputArray[RIGHTMOUSEHELD] = true;
35 else inputArray[RIGHTMOUSEHELD] = false;
36 //if (inputArray[MIDDLEMOUSECLICKED] == true) inputArray[MIDDLEMOUSEHELD] = true;
37 //else
38 inputArray[MIDDLEMOUSEHELD] = false; inputArray[MIDDLEMOUSECLICKED] = false;
39 if (inputArray[MOUSEWHEELUP] == true) inputArray[MOUSEWHEELUP] = false;
40 if (inputArray[MOUSEWHEELDOWN] == true) inputArray[MOUSEWHEELDOWN] = false;
41 while (SDL_PollEvent(&evnt)) {
42 switch (evnt.type) {
43 case SDL_QUIT:
44 inputArray[QUIT] = true;
45 break;
46 case SDL_MOUSEMOTION:
47 SDL_GetMouseState(x, y);
48 break;
49 case SDL_MOUSEWHEEL:
50 if (evnt.wheel.y > 0) {
51 inputArray[MOUSEWHEELUP] = true;
53 else if(evnt.wheel.y < 0) {
54 inputArray[MOUSEWHEELDOWN] = true;
56 case SDL_MOUSEBUTTONDOWN:
57 inputArray[MOUSECLICKED] = true;
58 if (evnt.button.button == SDL_BUTTON_LEFT)
59 inputArray[LEFTMOUSECLICKED] = true;
60 if (evnt.button.button == SDL_BUTTON_RIGHT)
61 inputArray[RIGHTMOUSECLICKED] = true;
62 if(evnt.button.button = SDL_BUTTON_MIDDLE)
63 inputArray[MIDDLEMOUSECLICKED] = true;
64 break;
65 case SDL_MOUSEBUTTONUP:
66 if (evnt.button.button == SDL_BUTTON_RIGHT)
67 inputArray[RIGHTMOUSECLICKED] = false;
68 if (evnt.button.button == SDL_BUTTON_LEFT)
69 inputArray[LEFTMOUSECLICKED] = false;
70 if(!(inputArray[RIGHTMOUSECLICKED] || inputArray[LEFTMOUSECLICKED]))
71 inputArray[MOUSECLICKED] = false;
72 if (!(evnt.button.button = SDL_BUTTON_MIDDLE))
73 inputArray[MIDDLEMOUSECLICKED] = false;
74 break;
77 return &inputArray;
80 void MouseIO::trackDestopMouse(int* x, int* y) {
81 SDL_GetGlobalMouseState(x, y);
84 void MouseIO::trackGameMouse(int* x, int* y) {
85 SDL_GetMouseState(x, y);
88 int MouseIO::calculateMouseDistance(int x, int y) {
89 int distance = 0;
90 if (oldX != -1) {
91 distance = sqrt(
92 (oldX - x) * (oldX - x) + (oldY - y) * (oldY - y)
94 distanceCounter += distance;
97 oldX = x;
98 oldY = y;
100 return distance;
103 void MouseIO::resetDistanceCounter() {
104 distanceCounter = 0; oldX = -1; oldY = -1;
108 //0 is exit pressed, 1 is held, 2 is clicked
109 //Returns a copy of the origional array
110 std::vector<bool> MouseIO::getInputArray() {
111 return inputArray;